#FROM centos:7
FROM --platform=arm64 centos:7
#COPY Centos-7.repo /etc/yum.repos.d/CentOS-Base.repo

RUN yum update -y
RUN yum install -y java-11-openjdk
#RUN yum install -y sed
#RUN yum install -y vim
#RUN yum install -y netstat
#RUN yum install -y net-tools
# /usr/share/thingsboard/

RUN mkdir -p  /usr/share/thingsboard/conf/
RUN mkdir -p /var/log/thingsboard/
COPY thingsboard-3.6.2-SNAPSHOT-boot.jar /usr/share/thingsboard/thingsboard.jar
#COPY thingsboard.rpm /tmp/
#
#RUN yum install -y /tmp/thingsboard.rpm && \
#    rm /tmp/thingsboard.rpm && \
#    yum clean all

COPY logback.xml thingsboard.yml  start-tb.sh /tmp/
#  upgrade-tb.sh install-tb.sh start-db.sh stop-db.sh

RUN chmod a+x /tmp/*.sh
RUN mv /tmp/start-tb.sh /usr/bin
RUN echo $(cat /tmp/logback.xml)
# && \
#    mv /tmp/upgrade-tb.sh /usr/bin && \
#    mv /tmp/install-tb.sh /usr/bin && \
#    mv /tmp/start-db.sh /usr/bin && \
#    mv /tmp/stop-db.sh /usr/bin

#RUN systemctl --no-reload disable --now thingsboard.service > /dev/null 2>&1 || :
RUN mv /tmp/logback.xml /usr/share/thingsboard/conf/logback.xml
RUN mv /tmp/thingsboard.yml /usr/share/thingsboard/conf/thingsboard.yml

ENV DATA_FOLDER=/data

ENV HTTP_BIND_PORT=9095
ENV DATABASE_TS_TYPE=sql

ENV PGDATA=/data/db
ENV PATH=$PATH:/usr/pgsql-12/bin

ENV SPRING_JPA_DATABASE_PLATFORM=org.hibernate.dialect.PostgreSQLDialect
ENV SPRING_DRIVER_CLASS_NAME=org.postgresql.Driver
ENV SPRING_DATASOURCE_URL=jdbc:postgresql://10.1.151.225:5432/newthingsboard
ENV SPRING_DATASOURCE_USERNAME=postgres
ENV SPRING_DATASOURCE_PASSWORD=Zyxk@123}
ENV PGLOG=/var/log/postgres
RUN groupadd thingsboard
RUN useradd -g thingsboard thingsboard
RUN mkdir -p $PGLOG
RUN chown -R thingsboard:thingsboard $PGLOG
RUN mkdir -p /data
RUN chown -R thingsboard:thingsboard /data
RUN chown -R thingsboard:thingsboard /var/log/thingsboard

EXPOSE 9090
EXPOSE 1883
EXPOSE 5683/udp

VOLUME ["/data"]

CMD ["java", "-jar", "/usr/share/thingsboard/thingsboard.jar"]
